/**
 * _ooOoo_
 * o8888888o
 * 88" . "88
 * (| -_- |)
 * O\  =  /O
 * ____/`---'\____
 * .'  \\|     |//  `.
 * /  \\|||  :  |||//  \
 * /  _||||| -:- |||||-  \
 * |   | \\\  -  /// |   |
 * | \_|  ''\---/''  |   |
 * \  .-\__  `-`  ___/-. /
 * ___`. .'  /--.--\  `. . __
 * ."" '<  `.___\_<|>_/___.'  >'"".
 * | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 * \  \ `-.   \_ __\ /__ _/   .-` /  /
 * ======`-.____`-.___\_____/___.-`____.-'======
 * `=---='
 * 佛祖保佑       永无BUG
 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 * Copyright (c) 2016,  email:14902300@qq.com All Rights Reserved.
 */
package com.fclassroom.logger.entity;

import com.jason.framework.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author jason
 * @date 2016年10月21日 下午10:36:14
 */
public final class LogCacheForSLS {
	protected static final Logger logger = LogManager.getLogger();

	/** 扩展为请求队列 */
	private ArrayBlockingQueue<String> logQueue;
	private ArrayBlockingQueue<String> studentLogQueueWeb;
	private ArrayBlockingQueue<String> studentLogQueueApp;
	private ArrayBlockingQueue<String> parentLogQueueWX;
	private ArrayBlockingQueue<String> teacherLogQueueWeb;
	private ArrayBlockingQueue<String> teacherLogQueuePC;
	private ArrayBlockingQueue<String> teacherLogQueueAPP;
	private ArrayBlockingQueue<String> reportLogQueueWeb;

	private ArrayBlockingQueue<LogRExamRead> logRExamReadQueue;

	public LogCacheForSLS(int maxCapacity) {
		logQueue = new ArrayBlockingQueue<String>(maxCapacity);
		logRExamReadQueue = new ArrayBlockingQueue<LogRExamRead>(maxCapacity);

		studentLogQueueWeb = new ArrayBlockingQueue<String>(maxCapacity);
		studentLogQueueApp = new ArrayBlockingQueue<String>(maxCapacity);
		parentLogQueueWX = new ArrayBlockingQueue<String>(maxCapacity);
		teacherLogQueueWeb = new ArrayBlockingQueue<String>(maxCapacity);
		teacherLogQueuePC = new ArrayBlockingQueue<String>(maxCapacity);
		teacherLogQueueAPP = new ArrayBlockingQueue<String>(maxCapacity);
		reportLogQueueWeb = new ArrayBlockingQueue<String>(maxCapacity);
	}

	public String pullReportWebLog() {
		return this.reportLogQueueWeb.poll();
	}

	public void putReportWebLog(String log) {
		try {
			this.reportLogQueueWeb.put(log);
			logger.info("put数据后，reportLogQueueWeb队列当前大小：" + reportLogQueueWeb.size());
		} catch (InterruptedException e1) {
			logger.error("reportLogQueueWeb操作日志放入队列出错：" + e1.getMessage());
		}
	}

	public String pullTeacherAppLog() {
		return this.teacherLogQueueAPP.poll();
	}

	public void putTeacherAppLog(String log) {
		try {
			this.teacherLogQueueAPP.put(log);
			logger.info("put数据后，teacherLogQueueAPP队列当前大小：" + teacherLogQueueAPP.size());
		} catch (InterruptedException e1) {
			logger.error("teacherLogQueueAPP操作日志放入队列出错：" + e1.getMessage());
		}
	}

	public String pullTeacherPCLog() {
		return this.teacherLogQueuePC.poll();
	}

	public void putTeacherPCLog(String log) {
		try {
			this.teacherLogQueuePC.put(log);
			logger.info("put数据后，teacherLogQueuePC队列当前大小：" + teacherLogQueuePC.size());
		} catch (InterruptedException e1) {
			logger.error("teacherLogQueuePC操作日志放入队列出错：" + e1.getMessage());
		}
	}

	public String pullTeacherWebLog() {
		return this.teacherLogQueueWeb.poll();
	}

	public void putTeacherWebLog(String log) {
		try {
			this.teacherLogQueueWeb.put(log);
			logger.info("put数据后，teacherLogQueueWeb队列当前大小：" + teacherLogQueueWeb.size());
		} catch (InterruptedException e1) {
			logger.error("teacherLogQueueWeb操作日志放入队列出错：" + e1.getMessage());
		}
	}

	public String pullParentWXLog() {
		return this.parentLogQueueWX.poll();
	}

	public void putParentWXLog(String log) {
		try {
			this.parentLogQueueWX.put(log);
			logger.info("put数据后，parentLogQueueWX队列当前大小：" + parentLogQueueWX.size());
		} catch (InterruptedException e1) {
			logger.error("parentLogQueueWX操作日志放入队列出错：" + e1.getMessage());
		}
	}

	public String pullStudentAppLog() {
		return this.studentLogQueueApp.poll();
	}

	public void putStudentAppLog(String log) {
		try {
			this.studentLogQueueApp.put(log);
			logger.info("put数据后，studentLogQueueApp队列当前大小：" + studentLogQueueApp.size());
		} catch (InterruptedException e1) {
			logger.error("studentLogQueueApp操作日志放入队列出错：" + e1.getMessage());
		}
	}

	public String pullStudentWebLog() {
		return this.studentLogQueueWeb.poll();
	}

	public void putStudentWebLog(String log) {
		try {
			this.studentLogQueueWeb.put(log);
			logger.info("put数据后，studentLogQueueWeb队列当前大小：" + studentLogQueueWeb.size());
		} catch (InterruptedException e1) {
			logger.error("studentLogQueueWeb操作日志放入队列出错：" + e1.getMessage());
		}
	}

	public String pullLog() {
		return this.logQueue.poll();
	}

	public void putLog(String log) {
		try {
			this.logQueue.put(log);
			logger.info("put数据后，队列当前大小：" + logQueue.size());
		} catch (InterruptedException e1) {
			logger.error("操作日志放入队列出错：" + e1.getMessage());
		}
		// 在数据部门还没有完成之前，以下代码还需要我们解析log内容去写入到数据库
		// //判断是否是登录操作
		// if (StringUtil.isNotBlank(operaterLog.getOperateUrl()) &&
		// (operaterLog.getOperateUrl().indexOf("loginBy") > -1 ||
		// operaterLog.getOperateCategory().indexOf("用户访问") > -1)) {
		// LogRLogin logRLogin = new LogRLogin(operaterLog);
		// if (logRLogin != null && logRLogin.getUserId() != null &&
		// logRLogin.getUserId() != 0) {
		// try {
		// logRLoginQueue.put(logRLogin);
		// } catch (InterruptedException e) {
		// logger.error("登录日志放入队列出错：" + e.getMessage());
		// }
		// }
		// }
		// 读卷 operateCategory=读卷
		// if ("读卷".equals(operaterLog.getOperateCategory()) &&
		// "上传读卷日志".equals(operaterLog.getOperateMethod())) {
		// LogRExamRead examRead = new LogRExamRead(operaterLog);
		// if (examRead != null && examRead.getExamId() != null) {
		// try {
		// logRExamReadQueue.put(examRead);
		// } catch (InterruptedException e) {
		// logger.error("读卷日志放入队列出错：" + e.getMessage());
		// }
		// }
		// }
	}
}